import { createApp } from "vue";
import App from "./app.vue";
import router from "./router/index";
import { Loading, Popup, Field, Button, Row, Col, Overlay } from "vant";
import "vant/lib/index.css";
// import VConsole from "vconsole";
import FontFaceObserver from "fontfaceobserver";

declare const cordova: unknown;

// const config = process.env.CONFIG as any;

function vueInit(): void {
  console.log("----this is vue init----");
  createApp(App)
    .use(router)
    .use(Loading)
    .use(Popup)
    .use(Field)
    .use(Button)
    .use(Row)
    .use(Col)
    .use(Overlay)
    .mount("#app");
  const font = new FontFaceObserver("ChangAnunitype");
  font.load("长安").then(() => {
    document.documentElement.className = "ChangAnunitype-loaded";
  });
}
// .provide('$appConfig', appConfig) // vite build 报错 [rollup-plugin-dynamic-import-variables] Unexpected token

/**
 * 根据环境初始化，宿主内需要device ready后才能初始化
 */
function init(): void {
  console.log("----main init----");
  // 初始化vconsole
  // if (config.env === "development" || config.env === "staging") {
  //   // eslint-disable-next-line no-unused-vars
  //   const vconsole = new VConsole();
  // }

  // 初始化VUE
  if (typeof cordova === "undefined") {
    vueInit();
  } else {
    document.addEventListener("deviceready", vueInit, false);
  }
}

init();
